package com.whfc.emp.manager.impl;



import org.json.JSONObject;
import com.baidu.aip.face.AipFace;
import com.whfc.emp.manager.FaceBaiDuManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * 百度人脸 api
 */
@Service
public class FaceBaiDuManagerImpl implements FaceBaiDuManager {

    @Resource(name = "baiDuAiFace")
    private AipFace baiDuAiFace;

    /**
     * 人脸库添加
     * @param image
     * @param deptId
     * @param empId
     * @return
     */
    @Override
    public JSONObject addUser(String image, String deptId, String empId) {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("quality_control", "LOW");
        options.put("liveness_control", "NORMAL");
        options.put("action_type", "REPLACE");
        return baiDuAiFace.addUser(image,"BASE64",deptId,empId,options);
    }

    /**
     * 人脸库搜索
     * @param image
     * @param deptId
     * @return
     */
    @Override
    public JSONObject search(String image, String deptId) {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("max_face_num", "3");
        options.put("match_threshold", "70");
        options.put("quality_control", "LOW");
        options.put("liveness_control", "NORMAL");
        options.put("max_user_num", "1");
        return baiDuAiFace.search(image,"BASE64",deptId,options);
    }

    /**
     * 删除人脸
     * @param deptId
     * @param empId
     * @return
     */
    @Override
    public JSONObject deleteUser(String deptId, String empId) {
        return baiDuAiFace.deleteUser(deptId,empId,new HashMap<>());
    }
}
